package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author: 夏帮连
 * @date: 2025/06/11
 * @description:
 * @version: 1.0
 */
@Mapper
public interface DishMapper {
    @Select("select d.* from dish d left join setmeal_dish sd on d.id = sd.dish_id where sd.setmeal_id=#{id}")
    List<Dish> getBySetmealId(Long id);

    @Select("select IFNULL(count(id), 0) from dish where category_id=#{id}")
    int countByCatoryId(Long id);
    @AutoFill(OperationType.INSERT)
    @Insert("INSERT INTO DISH (NAME, CATEGORY_ID, PRICE, IMAGE, DESCRIPTION, STATUS, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER) VALUES (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Dish dish);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);
    @Delete("delete from dish where id=#{id}")
    void deleteById(Long id);
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);
    @Select("select * from dish where category_id=#{categoryId} and status=#{status}")
    List<Dish> list(Dish dish);
    @Select("select IFNULL(count(id), 0) from dish where status=#{status}")
    Integer countByStatus(Integer status);
}
